package org.apache.flink.formats.json;

import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.formats.common.TimestampFormat;

import java.util.Set;

/**
 * @author guan
 * @date 2019/11/15
 */
public class JsonOptions {
    public static final ConfigOption<Boolean> FAIL_ON_MISSING_FIELD = JsonFormatOptions.FAIL_ON_MISSING_FIELD;
    public static final ConfigOption<Boolean> IGNORE_PARSE_ERRORS = JsonFormatOptions.IGNORE_PARSE_ERRORS;
    public static final ConfigOption<String> MAP_NULL_KEY_MODE = JsonFormatOptions.MAP_NULL_KEY_MODE;
    public static final ConfigOption<String> MAP_NULL_KEY_LITERAL = JsonFormatOptions.MAP_NULL_KEY_LITERAL;
    public static final ConfigOption<String> TIMESTAMP_FORMAT = JsonFormatOptions.TIMESTAMP_FORMAT;
    public static final ConfigOption<Boolean> ENCODE_DECIMAL_AS_PLAIN_NUMBER = JsonFormatOptions.ENCODE_DECIMAL_AS_PLAIN_NUMBER;

    public static final String SQL = JsonFormatOptionsUtil.SQL;
    public static final String ISO_8601 = JsonFormatOptionsUtil.ISO_8601;
    public static final Set<String> TIMESTAMP_FORMAT_ENUM = JsonFormatOptionsUtil.TIMESTAMP_FORMAT_ENUM;
    public static final String JSON_MAP_NULL_KEY_MODE_FAIL = JsonFormatOptionsUtil.JSON_MAP_NULL_KEY_MODE_FAIL;
    public static final String JSON_MAP_NULL_KEY_MODE_DROP = JsonFormatOptionsUtil.JSON_MAP_NULL_KEY_MODE_DROP;
    public static final String JSON_MAP_NULL_KEY_MODE_LITERAL = JsonFormatOptionsUtil.JSON_MAP_NULL_KEY_MODE_LITERAL;

    public static TimestampFormat getTimestampFormat(ReadableConfig config) {
        return JsonFormatOptionsUtil.getTimestampFormat(config);
    }

    public static JsonFormatOptions.MapNullKeyMode getMapNullKeyMode(ReadableConfig config) {
        return JsonFormatOptionsUtil.getMapNullKeyMode(config);
    }

    public static void validateDecodingFormatOptions(ReadableConfig tableOptions) {
        JsonFormatOptionsUtil.validateDecodingFormatOptions(tableOptions);
    }

    public static void validateEncodingFormatOptions(ReadableConfig tableOptions) {
        JsonFormatOptionsUtil.validateEncodingFormatOptions(tableOptions);
    }

    static void validateTimestampFormat(ReadableConfig tableOptions) {
        JsonFormatOptionsUtil.validateTimestampFormat(tableOptions);
    }

    private JsonOptions() {
    }

    public static class MapNullKeyMode {
        public static final JsonFormatOptions.MapNullKeyMode FAIL = JsonFormatOptions.MapNullKeyMode.FAIL;
        public static final JsonFormatOptions.MapNullKeyMode DROP = JsonFormatOptions.MapNullKeyMode.DROP;
        public static final JsonFormatOptions.MapNullKeyMode LITERAL = JsonFormatOptions.MapNullKeyMode.LITERAL;

        private MapNullKeyMode() {
        }
    }
}
